<%@ page language="java"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <title>部品列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!-- 引用新样式 start -->
    <jsp:include page="../../jsp/public.jsp" flush="true"/>
    <!-- end -->
    <script type="text/javascript" src="<%=basePath%>js/new/jquery.min.js" charset="utf-8"></script>
    <script>
        //提交表单
        function queryModelList() {
            var data = $("#queryForm").serialize();
            window.location.href = "<%=path%>/bus/plan/list?" + data;
        }

        //跳转到编辑页面
        function toEdit(id) {
        	$("#mapId").val(id);
        	/* var mapCode = $("#modelCode").val();
        	var mapFactory = $("#factory").val();
        	var mapType = $("#modelType").val();
        	var mapLevel = $("#modelLevel").val();
        	var mapStatus = $("#planStatus").val();

        	var data={
        			mapId:id,
        			mapCode:mapCode,
        			mapFactory:mapFactory,
        			mapType:mapType,
        			mapLevel:mapLevel,
        			mapStatus:mapStatus
        	}
        	var a = data.serialize(); */
        	var data = $("#queryForm").serialize();
          	window.location.href = "<%=path%>/bus/plan/toEdit?" + data;
        }

        function toView(id) {
        	$("#mapId").val(id);
        	var data = $("#queryForm").serialize();
            window.location.href = "<%=path%>/bus/plan/toView?" + data;
        }

        function toMeter(modelCode) {
            window.location.href = "<%=path%>/bus/plan/toMeter?modelCode=" + modelCode;
        }

        /* function updateModelStatus(id){
            var result = [];
            var data = {
                     id:id,
                    status:'无效'
                };
            result.push(data);
            var url = "/mpts/bus/plan/updateBusModelStatus";
            $.ajax({
                type : "post",
                url : url,
                data : {arr:JSON.stringify(result)},
                dataType : "json",
                success : function(data) {
                    window.location.reload()//刷新当前页面
                }
            });
        } */

        function showTipsLssued(id, modelId) {
            $("#modelPlanId").val(id);
            $("#modelId").val(modelId);
        }

        //下发
        function updateModelPlanStatus(id,modelId) {
        	layer.confirm('是否确认下发?', {offset: 't',icon: 3, title:'提示'}, function(index){
        		var loadId = layer.msg('下发中', {
        			icon: 16
        			,shade: 0.3,
        			offset: 't', //坐标
        			time:false
        		});
	            var result = [];
	            var data = {
	                id: id,
	                modelId: modelId,
	                status: '1'
	            };
	            result.push(data);
	            var url = "<%=path%>/bus/plan/effective";
	            $.ajax({
	                type: "post",
	                url: url,
	                data: {arr: JSON.stringify(result)},
	                dataType: "json",
	                success: function (data) {
	                	layer.close(loadId);//手动关闭
	                    //toastr.success('下发成功');
//	                    window.location.reload()//刷新当前页面
                        window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/bus/plan/list&flg=queryPlanList';
	                }
	            });
        	});
        }

        function showTipsLowerShelf(id) {
            $('#bxModal').modal('show');
            $("#modelPlanId").val(id);
        }
        function lowerShelf(id) {
	        layer.prompt({title: '请输入终止原因', formType: 2,offset:'t',value:''}, function(statusReason, index){
	            layer.close(index);
	            var result = [];
	            var data = {
	                id: id,
	                status: '2',
	                statusReason: statusReason
	            };
	            result.push(data);
	            var url = "<%=path%>/bus/plan/updateBusModelPlanStatus";
	            showLoad();
	            $.ajax({
	                type: "post",
	                url: url,
	                data: {arr: JSON.stringify(result)},
	                dataType: "json",
	                success: function (data) {
	                    //alert(data.message);
//	                    window.location.reload()//刷新当前页面
	                    window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/bus/plan/list&flg=queryPlanList';
	                }
	            });
	        });
        }
        //终止
     <%--    function lowerShelf() {
            var id = $("#modelPlanId").val();
            var statusReason = $("#statusReason").val();
            var result = [];
            var data = {
                id: id,
                status: '2',
                statusReason: statusReason
            };
            result.push(data);
            var url = "<%=path%>/bus/plan/updateBusModelPlanStatus";
            $.ajax({
                type: "post",
                url: url,
                data: {arr: JSON.stringify(result)},
                dataType: "json",
                success: function (data) {
                    //alert(data.message);
//                    window.location.reload()//刷新当前页面
                    window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/bus/plan/list&flg=queryPlanList';
                }
            });
        } --%>

        //修改频次
        function editReport(id, num) {
            $("#reportFreq").val(num);
            $('#myModalEdit').modal('show');
            $("#reportId").val(id);
        }

        //修改频次
        function determine() {
            var num = $("#reportFreq").val();
            var id = $("#reportId").val();
            var datas = {
                "reportFreq": num,
                "modelPlanId": id
            };
            $.ajax({
                url: '<%=path%>/bus/progress/editReport',
                data: datas,
                type: 'post',
                cache: false,
                async: false,
                success: function (data) {
                    var infoss = data.infoss;
                    if (infoss == 1) {
                        $("#infos").text("汇报频数大于0");
                    } else {
                        $('#myModalEdit').modal('hide');
                        alert("更改成功！");
//                        window.location.reload()//刷新当前页面
                        window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/bus/plan/list&flg=queryPlanList';
                    }
                },
                error: function (data) {
                    alert("更改出错!");
                }
            });
        }

        function improtExcel() {
            $('#myModalImp').modal('show');
        }

        //Excel文件导入到数据库中
        function importEmp(){
            //检验导入的文件是否为Excel文件
            var uploadFile = document.getElementById("uploadFile").value;
            if(uploadFile == null || uploadFile == ''){
                alert("请选择要上传的Excel文件");
                return;
            }else{
                var fileExtend = uploadFile.substring(uploadFile.lastIndexOf('.')).toLowerCase();
                if(fileExtend == '.xls'||fileExtend == '.xlsx'){
                }else{
                    alert("文件格式需为'.xls'格式");
                    return;
                }
            }
            //提交表单
            document.getElementById("from1").submit();
            //加载层
            $('#myModalImp').modal('hide');
            $('#loading').modal('show');
        }

    </script>
<body>

<input type="hidden" class="hiddenId" id="modelPlanId" value="">
<input type="hidden" class="hiddenId" id="modelId" value="">
<div class="col-lg-12">
    <div class="index-nav-right">
        <div class="index-nav-right-header"><span>当前位置 > 金型进度管理 > <b>金型计划查询</b></span></div>
    </div>
    <div class="right-table">
        <div style="border:0px solid red;">
            <span style="float: right;margin-top: 10px;margin-right: 10px;" class="hand-like" onClick="improtExcel()">
                批量导入
            </span>
        </div>
        <form id="queryForm" method="post" action="<%=path%>/bus/plan/list">
        	<input hidden = "true" type = "text" id = "mapId" name = "mapId">
        	<input hidden = "true" type = "text" id = "mapPage" name ="mapPage" value="${map['page'] }">
            <div class="search-form">
                <div class="search-form-input">
                    <label>厂商名称</label>
                    <select name="factory" id="factory">
                        <option value="">请选择</option>
                        <c:if test="${not empty factoryList}">
                            <c:forEach items="${factoryList }" var="factoryList"
                                       varStatus="m">
                                <option value="${factoryList.orgCode}"
                                        <c:if test="${map['factory'] ==factoryList.orgCode }">selected</c:if>>${factoryList.orgName}</option>
                            </c:forEach>
                        </c:if>
                    </select>
                </div>
                <div class="search-form-input">
                    <label>机种:</label>
                    <select name="modelType" id="modelType">
                    	<option value="">请选择</option>
                    	<c:if test="${not empty mTypeList}">
                            <c:forEach items="${mTypeList }" var="mTypeList"
                                       varStatus="m">
                                <option value="${mTypeList.targetName}"
                                        <c:if test="${map['modelType'] ==mTypeList.targetName }">selected</c:if>>${mTypeList.targetName}</option>
                            </c:forEach>
                        </c:if>
                    </select>
                </div>
                <div class="search-form-input" style="border: 0px solid red">
                    <label>难易度:</label>
                    <select name="modelLevel" id="modelLevel">
                        <option value="" <c:if test="${map['modelLevel'] =='' }">selected</c:if>>请选择</option>
                        <option value="S" <c:if test="${map['modelLevel'] =='S' }">selected</c:if>>S</option>
                        <option value="A" <c:if test="${map['modelLevel'] =='A' }">selected</c:if>>A</option>
                        <option value="B" <c:if test="${map['modelLevel'] =='B' }">selected</c:if>>B</option>
                        <option value="C" <c:if test="${map['modelLevel'] =='C' }">selected</c:if>>C</option>
                    </select>
                </div>
                <div class="search-form-input">
                    <label>部品番号</label><input type="text" name="modelCode" id="modelCode"
                                              value="${map['modelCode'] }"/>
                </div>

                <div class="search-form-btn search-form-input">
                    <button type="submit" style="color: black;" class="btn btn-primary search-form-btn-s">搜索</button>
                </div>
            </div>
			<div class="search-form">
				<div class="search-form-input">
                    <label>状态</label>
                    <select
                            name="planStatus" id="planStatus">
                        <option value="" <c:if test="${map['planStatus'] =='' }">selected</c:if>>请选择</option>
                        <option value="0" <c:if test="${map['planStatus'] =='0' }">selected</c:if>>未提交</option>
                        <option value="1" <c:if test="${map['planStatus'] =='1' }">selected</c:if>>已下发</option>
                        <option value="2" <c:if test="${map['planStatus'] =='2' }">selected</c:if>>已完成</option>
                    </select>
                </div>
			</div>
        </form>
            <div class="index-table">
                <table class="table table-striped" action="<%=path%>/bus/plan/list">
                    <thead>
                    <tr class="table-thead">
                        <th>序号</th>
                        <th>厂商</th>
                        <th>机种</th>
                        <th>难易度</th>
                        <th>部品番号</th>
                        <th>所属客户</th>
                        <th>计划状态</th>
                        <th>计划开始</th>
                        <th>计划结束</th>
                        <th>实际开始</th>
                        <th>实际结束</th>
                        <th>是否<br/>接收</th>
                        <th>进度提交时间</th>
                        <th>汇报频次</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:if test="${not empty list}">
                        <c:forEach items="${list }" var="model" varStatus="r">
                            <tr>
                                <td>${r.index+1 }</td>
                                <td>${model.factory }</td>
                                <td>${model.modelType }</td>
                                <td>${model.modelLevel }</td>
                                <td>${model.modelCode }</td>
                                <td>${model.customer }</td>
                                <td>${model.planStatusText }</td>
                                <td>${model.planStartTimeText }</td>
                                <td>${model.planEndTimeText }</td>
                                <td>${model.accStartTime }</td>
                                <td>${model.accEndTime }</td>
                                <td>${model.receiveFlag=='1'?'已接收':'未接收'}</td>
                                <td>${model.lastReportTimeText }</td>
                                <td>
                                    <c:if test="${model.planStatusText != '已完成'}">
                                        <c:if test="${model.reportFreq!=null }">
                                            <c:if test="${model.planStatusText != '未提交'}">
                                            每${model.reportFreq }天
                                            </c:if>
                                        </c:if>
                                    </c:if>
                                </td>
                                <td id="${model.id }">
                                    <span name="editModel"
                                          class="hand-like"
                                          onClick='toEdit("${model.id}")' >修改</span>
                                    <span name="viewModel" class="hand-like" onClick="toView('${model.id }')">详情</span>
                                    <span <c:if test="${model.planStatusText == '未提交'}">class="hand-like"
                                          onClick='updateModelPlanStatus("${model.modelPlanId}", "${model.id }")'
                                          </c:if>>下发</span>
                                    <span name="editStatus"
                                          <c:if test="${model.planStatusText != '已完成'}">class="hand-like"
                                          onClick='lowerShelf("${model.modelPlanId}")' </c:if>>终止</span>
                                    <br/>
                                    <span <c:if test="${model.planStatusText != '已完成'}">class="hand-like"
                                          onClick='toMeter("${model.modelCode }")' </c:if>
                                            >材料入库</span>

                                    <span
                                            <c:if test="${model.planStatusText != '已完成'}">class="hand-like"
                                            onClick="editReport(${model.modelPlanId},${model.reportFreq })" </c:if>
                                          >
                                       <c:if test="${model.planStatusText != '未提交'}">
                                           更改频次
                                       </c:if>
                                    </span>
                                </td>
                            </tr>
                        </c:forEach>
                    </c:if>
                    <c:if test="${empty list}">
                        <tr>
                            <td colspan="15"><label class="control-label text-center">无记录</label></td>
                        </tr>
                    </c:if>
                    </tbody>
                    <tr style="background: #f8f8f8">
                        <td colspan="15">
                            <jsp:include page="/WEB-INF/jsp/page.jsp"></jsp:include>
                        </td>
                    </tr>
                </table>
            </div>
    </div>
</div>

<div class="modal fade" id="bxModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-tbxb" style=" top:50%; margin-top:-50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body">
                <div class="form-group financialRisk" style="text-align:center;">
                    请填写终止原因:<input type="text" id="statusReason" value="">
                </div>
                <ul class="col-btn-12">
                    <li style="text-align:center">
                        <button type="button" class="btn-primary btn" id="" data-dismiss="modal" aria-hidden="true"
                                onClick="lowerShelf()">确认
                        </button>
                        <button type="button" class="btn-default btn" data-dismiss="modal" aria-hidden="true">取消
                        </button>

                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="lssuedTips" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-tbxb" style=" top:50%; margin-top:-50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body">
                <div class="form-group financialRisk" style="text-align:center;">
                    是否确认下发？
                </div>
                <ul class="col-btn-12">
                    <li style="text-align:center">
                        <button type="button" class="btn-primary btn" id="" data-dismiss="modal" aria-hidden="true"
                                onClick="updateModelPlanStatus()">确认
                        </button>
                        <button type="button" class="btn-default btn" data-dismiss="modal" aria-hidden="true">取消
                        </button>

                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

<!-- 修改频次 模态框（Modal） -->
<div class="modal fade" id="myModalEdit" tabindex="-10" role="dialog" aria-labelledby="myModalLabelEdit"
     aria-hidden="true" style="border: 0px solid red">
    <div class="modal-dialog" style="border: 0px solid red;margin-top: 120px; ">
        <div class="modal-content" style="border: 0px solid red; width: 60%;margin: auto;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h3 class="modal-title" id="myModalLabelEdit">
                    邮件提醒频次修改
                </h3>
            </div>
            <form id="defaultForm"
                  class="form-horizontal"
                  method="post" style="border: 0px solid red;">
                <div class="modal-body">

                    <div class="form-group">
                        <label class="col-sm-2 control-label">次数:</label>
                        <div class="col-sm-5">
                            <input type="hidden" id="reportId"/>
                            <input type="number" class="form-control" id="reportFreq" name="reportFreq"
                                   placeholder="" required/>
                            <p style="color:red;" id="infos"></p>
                        </div>

                    </div>

                </div>
                <div class="modal-footer">
                    <button id="editDetermine" type="button" class="btn btn-success" onclick="determine()">确定
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>

                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div><!-- /.end modal -->

<!-- 导入 模态框（Modal） -->
<div class="modal fade" id="myModalImp" tabindex="-11" role="dialog" aria-labelledby="myModalLabelImp"
     aria-hidden="true" style="border: 0px solid red">
    <div class="modal-dialog" style="border: 0px solid red;margin-top: 120px; ">
        <div class="modal-content" style="border: 0px solid red; width: 60%;margin: auto;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h3 class="modal-title" id="myModalLabelImp">
                    批量导入
                </h3>
            </div>
            <form id="from1" action="<%=path%>/bus/plan/improtExcel" enctype="multipart/form-data"
                  class="form-horizontal"
                  method="post" style="border: 0px solid red;">
                <div class="modal-body">

                    <div class="form-group">
                        <div class="col-sm-5">
                            <input type="file" id="uploadFile" name="uploadFile"/>
                        </div>

                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" onclick="importEmp()">确定
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div><!-- /.end modal -->

<!-- loading -->
<div class="modal fade" id="loading" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop='static' >
    <div class="modal-dialog" role="document" style="border: 0px solid red; margin-top: 160px;">
        <div class="modal-content" style="border: 0px solid red; width: 60%;margin: auto;">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">提示</h4>
            </div>
            <div class="modal-body">
                导入中请稍后......
            </div>
        </div>
    </div>
</div>

</div>
</div>
</body>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
</html>